DP B
DP_B
code:python
def solve(N, K, heights):
for i in range(N - 1):
for k in range(1, K + 1):
costsi + abs(heightsi + k - heightsi)) ところが3TLE
下記のように関数呼び出しを削ったが1TLE残った
Numbaでコンパイルしようかと思ったが
PyPyで提出、165msec AC
code:python
def solve(N, K, heights):
for i in range(N - 1):
for k in range(1, K + 1):
newcost = costsi + abs(heightsi + k - heightsi) 1625 ms AC
PyPy 385 ms
code:python
def solve(N, K, heights):
for i in range(1, N):
costsj + abs(heightsi - heightsj) for j in range(max(i - K, 0), i)
)
8TLE
PyPy 540 ms AC
code:python
def solve(N, K, heights):
def get_cost(i):
c = min(
get_cost(j) + abs(heightsi - heightsj) for j in range(max(i - K, 0), i)
)
return c
return get_cost(N - 1)